<?php

namespace App\Models\Store;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * Class StorePivotWechatUser
 * @package App\Models\Store
 * @mixin Builder
 */
class StorePivotWechatUser extends Model
{
    protected $table = 'store_pivot_wechat_user';

    protected $guarded = [];

    /**
     * @param array $store_ids
     *
     * @return array
     */
    public static function storesWechatUsersIds(array $store_ids): array
    {
        return (new self)
            ->whereIn('store_id', $store_ids)
            ->pluck('wechat_user_id')
            ->unique()
            ->all();
    }

    /**
     * @param int $wechat_user_id
     *
     * @return array
     */
    public static function wechatUserStoreIds(int $wechat_user_id): array
    {
        return (new self)
            ->where('wechat_user_id', $wechat_user_id)
            ->pluck('store_id')
            ->unique()
            ->all();
    }
}